 package {
	
	import flash.display.BitmapData;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.scenes.MovieScene3D;
	//import org.papervision3d.cameras.Camera3D;
	import fr.mk25.papervision3d.cameras.AdvancedFreeCamera3D;
	import fr.mk25.papervision3d.core.Position3D;
	import org.papervision3d.objects.*;
	import org.papervision3d.materials.*;
	import org.papervision3d.utils.*;
	import org.papervision3d.objects.Sphere;

    import flash.text.TextField;
    import flash.system.System;

	import flash.events.Event;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.BlendMode;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.geom.Matrix;

	[SWF(backgroundColor="0xFFFFFF", frameRate="31")]
	public class AdvancedFreeCamera3DTest extends Sprite 
	{		
		protected var container 				:Sprite;
		protected var scene     				:MovieScene3D;
		protected var camera   					:AdvancedFreeCamera3D;
		protected var ism						:InteractiveSceneManager;
		protected var plane	 	 				:Plane;
        private var memory_load                 :TextField; 
		
		public function AdvancedFreeCamera3DTest() {
			init();
		}
		public function init():void {
            memory_load = new TextField();
            memory_load.x = 0;
            memory_load.y = 0;
            memory_load.width = 300;
            memory_load.text = "Memory used: undefined";
 
            addChild(memory_load);


			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			init3D();
			createPlane();
			addEventListener(Event.ENTER_FRAME, loop);
		}
		protected function init3D():void {
			container = new InteractiveSprite();
			addChild(container);
			container.name = "mainCont";
			container.x = stage.stageWidth*.5;
			container.y = stage.stageHeight*.5;
	
			scene = new MovieScene3D(container);
			
			camera = new AdvancedFreeCamera3D();
			camera.zoom = 3;
			camera.focus = 500;

            trace(camera.getPosition3D().toString());

            var p:Position3D = new Position3D(0, 0, -2000, 0, 0, 30);
            var p1:Position3D = new Position3D(200, 0, -1500, 0, 0, 0)
            var p2:Position3D = new Position3D(-200, 0, -1700, 0, 0, 0);
            camera.move(p, camera.getPosition3D(), null, 5, "linear");

		}
		protected function createPlane():void {
			var material:WireframeMaterial = new WireframeMaterial(0x00ff00, 1);
			
			var plane:Plane = new Plane( material, 500, 500, 8, 8 );
			scene.addChild(plane);
		}
		protected function loop(event:Event):void {
			//camera.x = -(container.mouseX * 3)/2;
			//camera.y = (container.mouseY * 3);
			scene.renderCamera(camera);
            var memoryBytes:Number = System.totalMemory/1048576;            
            memory_load.text = "Memory used: " + memoryBytes.toString()     +"MBytes";

		}
	}
}



